<template>
  <view id="productID">
    <view>
      <TableTitle :title="'出厂模拟数据'" @click="openVideo"></TableTitle>
    </view>
    <view class="tableContentClass">
      <transition-group name="fade" tag="ul">
        <template v-for="(item, index) in dataLists" :key="index">
          <view class="tableClass" v-if="!item.isReplacing">
            <li>{{ index + 1 }}</li>
            <li>{{ item.code }}</li>
            <!-- <li>{{ formatDate(item.last_select_date, 'YY年MM月DD') }}</li> -->
          </view>
        </template>
      </transition-group>
    </view>
    <view class="pageClass" style="color: #000 !important"></view>
  </view>
</template>

<script setup lang="ts">
import TableTitle from '../TableTitle/TableTitle.vue'
import { formatDate, timeNumber, timeDiff } from '@/utils/days'
import {
  getAllDataAPI,
  getShuiAllDataAPI,
  getTeaDataAPI,
  getpackagesDataAPI,
  getclothesDataAPI,
  getshoesDataAPI,
  getlangDataAPI,
  getmilkDataAPI,
  getLiBangDataAPI,
} from '@/services/allData'
import { useyanZhengStore } from '@/stores/modules/yanZheng'
import { useWebsocketStore } from '@/stores/modules/websocket'
import { useVideoStore } from '@/stores/modules/video'
const yanZhengStore = useyanZhengStore()
const dataLists = ref(new Array())

async function getData() {
  // const res: any = await getAllDataAPI() //获取茅台数据
  // const res: any = await getShuiAllDataAPI() //获取水数据
  // const res: any = await getTeaDataAPI() //获取茶数据
  // const res: any = await getpackagesDataAPI() //获取包数据
  // const res: any = await getclothesDataAPI() //获取衣服数据
  // const res: any = await getshoesDataAPI() //获取鞋子数据
  // const res: any = await getlangDataAPI() //获取郎酒数据
  // const res: any = await getmilkDataAPI() //获取牛奶数据
  const res: any = await getLiBangDataAPI() //获取立邦数据
  console.log(res.data.data)
  let lists = res.data.data
  dataLists.value = lists.map((item: any) => {
    // item.add('isReplacing', false)
    return { ...item, isReplacing: false }
  })
}
getData()

function openVideo() {
  useVideoStore().date = Math.random()
  console.log(Math.random())
}

watch(
  () => useWebsocketStore().date,
  () => {
    getData()
  },
)

const items = ref(new Array())
const nextId = ref(11)

watch(
  () => yanZhengStore.code,
  () => {
    removeItem(yanZhengStore.code)
  },
)

function removeItem(item: any) {
  console.log('item', item)
  const index = dataLists.value.findIndex((i) => i.code == item[1])
  let data = { ...dataLists.value[index] }
  data.code = item[0]
  yanZhengStore.data = data
  console.log('找到了', index)
  if (index !== -1) {
    // 标记为正在替换
    dataLists.value[index].isReplacing = true

    setTimeout(() => {
      // 移除旧项，并在同一位置添加新项
      dataLists.value.splice(index, 1, data)
      nextId.value++
    }, 500) // 确保这个延时与.fade-leave-active的持续时间一致
  }
}

const inter = ref()
onMounted(() => {})
onUnmounted(() => {
  clearInterval(inter.value)
})
</script>

<style lang="scss" scoped>
#productID {
  height: 85vh;
  width: 30vw;
  background: url('../../static/images/Large_Content_Box.png') no-repeat;
  background-size: 100% 100%;
  position: relative;
  padding: 0 1vw;
  margin-top: 10px;

  .tableContentClass {
    margin-top: 30px;
    background: #0000;
    height: 94%;
    overflow-y: scroll;
    // overflow-y: hidden;
    &::-webkit-scrollbar {
      display: none;
    }

    ul {
      padding-inline-start: 0 !important;
    }

    .tableClass {
      margin: 5px 0 !important;
      padding: 0 1vw !important;
      background: url('../../static/images/Small_content_box.png') no-repeat;
      background-size: 100% auto;
      background-position: calc(50%);
      height: 7.2vh;
      display: flex;
      flex-direction: row;
      justify-content: space-between;
      align-items: center;

      li {
        color: #0ff;
        // height: 100%;
        display: inline-block;
        &:nth-child(2n) {
          width: 90% !important;
        }
        &:nth-child(2n-1) {
          width: 10% !important;
        }
      }
    }

    // :deep(.uni-table) {
    //   background-color: #fff0 !important;
    //   height: 520px;

    //   .uni-table-tr {
    //     margin: 5px 0 !important;
    //     background: url('../../static/images/Small_content_box.png') no-repeat;
    //     background-size: 100% auto;
    //     background-position: calc(50%);

    //     .uni-table-th,
    //     .uni-table-td {
    //       color: #0ff !important;
    //       border: none !important;
    //       box-sizing: border-box;
    //       // border-left: 1px #fff solid !important;
    //       // margin: 10px 0 !important;
    //       padding: 6px 10px !important;
    //       text-align: center;
    //       align-items: center;
    //     }

    //     .uni-table-td {
    //       .tdClass {
    //         height: 40px !important;
    //         display: flex;
    //         justify-content: center;
    //         align-items: center;
    //       }
    //     }

    //   }
    // }
  }
}

.fade-enter-active,
.fade-leave-active {
  transition: opacity 0.5s ease;
}

.fade-enter-from,
.fade-leave-to {
  opacity: 0.1;
}
</style>
